<?php

namespace app\index\controller;

use app\index\model\NewsModel;
use think\Request;
use think\View;

class Strategy extends Base {
    public function __construct(Request $request) {
        parent::__construct($request);
        View::share ('menuNow', '/strategy.html');
    }

    /**
     * @param Request $request
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function lists(Request $request) {
        $newsModel = new NewsModel();
        $map       = [];
        $type      = $request->get('type');
        if (!empty($type)) $map['n.type'] = $type;
        else $map['type'] = ['in', '3'];
        $list = $newsModel->getList($map, $request->get('page'), 5);
        return view('lists', [
            'list' => $list,
        ]);
    }

    /**
     * @param Request $request
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function detail(Request $request) {
        $id        = $request->route('id');
        $newsModel = new NewsModel();
        $detail    = $newsModel->getDetails(['n.id' => $id]);
        return view('detail', [
            'title'       => $detail['title'] . ',',
            'detail'      => $detail,
            'description' => $detail['description'] . ',',
        ]);
    }
}
